package com.deparse.mydialog.animation;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.deparse.mydialog.R;
import com.deparse.mydialog.common.BaseActivity;

/**
 * Created by Administrator on 2016/7/19.
 */
public class AllBaseAnimationActivity extends BaseActivity {
    private ImageView image_flip0, image_flip1, image_flip2, image_flip3, image_flip4, image_flip5, image_flip6, image_flip7;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_animation);
        image_flip0 = (ImageView) findViewById(R.id.image_flip0);
        image_flip1 = (ImageView) findViewById(R.id.image_flip1);
        image_flip2 = (ImageView) findViewById(R.id.image_flip2);
        image_flip3 = (ImageView) findViewById(R.id.image_flip3);
        image_flip4 = (ImageView) findViewById(R.id.image_flip4);
        image_flip5 = (ImageView) findViewById(R.id.image_flip5);
        image_flip6 = (ImageView) findViewById(R.id.image_flip6);
        image_flip7 = (ImageView) findViewById(R.id.image_flip7);


        image_flip0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(image_flip0, "alpha", 1, 0, 1);
                animator.setDuration(2000);
                animator.start();
            }
        });
        image_flip1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator anim = ObjectAnimator//
                        .ofFloat(image_flip1, "zhy", 1.0F, 0.0F, 1.0F)//
                        .setDuration(1000);//
                anim.start();
                anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        float cVal = (Float) animation.getAnimatedValue();
                        image_flip1.setAlpha(cVal);
                        image_flip1.setScaleX(cVal);
                        image_flip1.setScaleY(cVal);
                    }
                });
            }
        });
        image_flip2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(image_flip2, "rotationX", 0, 360, 0);
                animator.setDuration(2000);
                animator.start();
            }
        });
        image_flip3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(image_flip3, "rotationY", 0, 360, 0);
                animator.setDuration(2000);
                animator.start();
            }
        });
        image_flip4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(image_flip4, "scaleX", 0, 30, 1);
                animator.setDuration(2000);
                animator.start();
            }
        });
        image_flip5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(image_flip5, "scaleY", 0, 360, 1);
                animator.setDuration(2000);
                animator.start();

                ObjectAnimator animator1 = ObjectAnimator.ofFloat(image_flip6, "translationY", 0, -500, 0);
                animator1.setDuration(2000);
                animator1.start();

                ObjectAnimator animator2 = ObjectAnimator.ofFloat(image_flip7, "translationY", 0, 360, 0);
                animator2.setDuration(2000);
                animator2.start();

            }
        });
        image_flip6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(image_flip6, "translationX", 0, 360, 0);
                animator.setDuration(2000);
                animator.start();
            }
        });

        image_flip7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(image_flip7, "translationY", 0, 360, 0);
                animator.setDuration(2000);
                animator.start();
            }
        });
    }
}
